/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.qc.web;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.utils.excel.ExportExcel;
import com.thinkgem.jeesite.modules.food.entity.FoodInfo;
import com.thinkgem.jeesite.modules.food.entity.FoodInfoSupplierSublist;
import com.thinkgem.jeesite.modules.food.entity.FoodMarketResearchSublist;
import com.thinkgem.jeesite.modules.food.entity.FoodOrderForm;
import com.thinkgem.jeesite.modules.qc.entity.Automobile;
import com.thinkgem.jeesite.modules.qc.entity.InvestmentDecisions;
import com.thinkgem.jeesite.modules.qc.entity.SeniorAssets;
import com.thinkgem.jeesite.modules.qc.service.InvestmentDecisionsService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;
import com.thinkgem.jeesite.modules.test.entity.ReturnData;
//import com.thinkgem.jeesite.modules.qc.entity.WarntimeData;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 项目投资决策investmentDecisions
 * @author  
 * @version 2021-04-12
 * @param <THsapDaAttachment>
 */
@Controller
@RequestMapping(value = "${adminPath}/qc/investmentDecisions")
public class InvestmentDecisionsController<THsapDaAttachment>  extends BaseController {

	private static final String RandomUtil = null;
	private static final int UPLOAD_FILE_PATH = 0;
	private static final InvestmentDecisions Accessory = null;
	private static final String NASUtils = null;
	private static final String MultiFileUtils = null;
	@Autowired
	private	InvestmentDecisionsService investmentDecisionsService;
	/*private Date decisionDate;
	private Date enddate;
	private String phase;
	private InvestmentDecisions investmentDecisions;
	private Object tHsapDaAttachmentService;
	private JSONObject investmentDecisionsList;
	private String result;
	private String name;*/
	@ModelAttribute
	public InvestmentDecisions  get(@RequestParam(required=false) String id) {
		InvestmentDecisions entity = null;
		if (StringUtils.isNotBlank(id)){
			entity =investmentDecisionsService.get(id);
		}
		if (entity == null){
			entity = new InvestmentDecisions();
		}
		return entity;
	}
	@ResponseBody
	@RequestMapping(value = {"listByAjax"})
	public String listByAjax(HttpServletRequest request, HttpServletResponse response, Model model)throws ParseException {
		String decisionDate = request.getParameter("decisionDate");
		String endDate = request.getParameter("endDate");
		InvestmentDecisions investmentDecisions = new InvestmentDecisions();
		
		/*investmentDecisions.setPhase(phase);
		investmentDecisions.setEndDate(enddate);*/
/*		seniorAssets.setPhone(phone);*/
		if(decisionDate != null && !decisionDate.equals("") && endDate != null && !endDate.equals("")){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			investmentDecisions.setDecisionDate(sdf.parse(decisionDate));
			investmentDecisions.setEndDate(sdf.parse(endDate));
		}
		 
		List<InvestmentDecisions> seniorAssetsList = investmentDecisionsService.findList(investmentDecisions);
	 
		ReturnData returnData = new ReturnData();
		returnData.setCode("0");
		returnData.setCount(String.valueOf(seniorAssetsList.size()));
		returnData.setData(seniorAssetsList);
		String jsonData = JSON.toJSONString(returnData);
		System.out.println(jsonData);
		return jsonData;
	}
 
 
	@RequestMapping(value = {"list", ""})
	public String list(InvestmentDecisions investmentDecisions, HttpServletRequest request, HttpServletResponse response, Model model) {
		return "modules/qc/investmentDecisionsList";
	}
 
 
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(String dataString, Model model, RedirectAttributes redirectAttributes) {
		dataString = StringEscapeUtils.unescapeHtml4(dataString);
		InvestmentDecisions investmentDecisions = JSON.parseObject(dataString,InvestmentDecisions.class);
		investmentDecisionsService.save(investmentDecisions);
		String status =  JSON.toJSONString("保存数据成功");
		return status;
	}
	
	/**
	 * 导出用户数据
	 * @param user
	 * @param request
	 * @param response
	 * @param redirectAttributes
	 * @return
	 */
	
	@RequestMapping(value = "btnexport", method=RequestMethod.POST)
    public String export(InvestmentDecisions investmentDecisions, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String export = "用户财产数据"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
       	 	List<InvestmentDecisions> list = investmentDecisionsService.findList(investmentDecisions);
//            List<Financial> list = financialService.findList(financial);
     		new ExportExcel("用户财产数据", InvestmentDecisions.class).setDataList(list).write(response, export).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导出用户失败！失败信息："+e.getMessage());
		}
		return "redirect:" + adminPath + "/qc/investmentDecisions/list?repage";
    }
 
	@RequestMapping(value = "form")
	public String form(InvestmentDecisions investmentDecisions, Model model) {
		model.addAttribute("InvestmentDecisions", investmentDecisions);
		return "modules/qc/investmentDecisionsForm";
	}
 
	
	@ResponseBody
	@RequestMapping(value = "deleteById")
	public String delete(String id, RedirectAttributes redirectAttributes) {
		InvestmentDecisions investmentDecisions = new InvestmentDecisions();
		investmentDecisions.setId(id);
		investmentDecisionsService.delete(investmentDecisions);
		String status =  JSON.toJSONString("删除伙食支出成功");
		return status;
	}
	
	
	 
	
	 
}